import type { Rule } from 'ant-design-vue/es/form'

const validateUsername = async (_rule: Rule, value: string) => {
  if (value.length <= 0) {
    return Promise.reject('用户名不可为空')
  } else {
    return Promise.resolve()
  }
}

const validatePassword = async (_rule: Rule, value: string) => {
  if (value === '') {
    return Promise.reject('密码不可为空')
  } else {
    return Promise.resolve()
  }
}

const loginFormRules: Record<string, Rule[]> = {
  username: [
    {
      required: true,
      validator: validateUsername,
      trigger: 'change'
    }
  ],
  password: [{ required: true, validator: validatePassword, trigger: 'change' }]
}

export { loginFormRules }
